package com.yugao.fintech.antelope.infra.weixin.mp.handler.wx.other;

import com.yugao.fintech.antelope.infra.weixin.mp.handler.scanbiz.BaseWxScanEventHandler;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 扫码的事件处理器
 */
@Slf4j
@Component
public class ScanHandler implements WxMpMessageHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> context,
                                    WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
        try {
            String openId = wxMpXmlMessage.getFromUser();
            String eventKey = wxMpXmlMessage.getEventKey();
            log.info("openId: {}, eventKey: {}", openId, eventKey);

            BaseWxScanEventHandler.handle(wxMpXmlMessage, eventKey);
//        throw new UnsupportedOperationException("未实现该处理，请自行重写");
        } catch (Exception e) {
            log.error("error: ", e);
        }
        return null;
    }

}
